﻿CREATE PROCEDURE [dbo].[InsertPatient]
	@name NVARCHAR(50),	
	@gender NVARCHAR(10),
	@dateOfBirth DATE,
	@phoneNumber NVARCHAR(30),
	@emailAddress NVARCHAR(30),
	@homeAddressLine1 NVARCHAR(100),
	@homeAddressLine2 NVARCHAR(100),
	@homeAddressCity NVARCHAR(30),
	@homeAddressState NVARCHAR(30),
	@homeAddressPostalCode NVARCHAR(10),
	@medicalRecordNumber INT OUTPUT
AS	
	SELECT @medicalRecordNumber = ISNULL(MAX(MedicalRecordNumber), 0) + 1 FROM Patient

	INSERT INTO [dbo].[Patient]
           ([Name],
			[MedicalRecordNumber],
			[Gender],
			[DateOfBirth],
			[PhoneNumber],
			[EmailAddress],
			[HomeAddressLine1],
			[HomeAddressLine2],
			[HomeAddressCity],
			[HomeAddressState],
			[HomeAddressPostalCode])
     VALUES
           (@name,
			@medicalRecordNumber,
			@gender,
			@dateOfBirth,
			@phoneNumber,
			@emailAddress,
			@homeAddressLine1,
			@homeAddressLine2,
			@homeAddressCity,
			@homeAddressState,
			@homeAddressPostalCode
		   )	
RETURN 0
